﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SNSpirit.Documents.Adatpers.Ubb.Internal
{
	/// <summary>
	/// Helper class for push and pop style automatically with "using" statements.
	/// </summary>
	internal class ElementStylePushContext : IDisposable
	{

		/// <summary>
		/// The internal stack.
		/// </summary>
		private ElementStyleStack _Stack;

		/// <summary>
		/// Initialize a new style push context.
		/// </summary>
		/// <param name="stack">The stack to pushing the style.</param>
		/// <param name="style">The style to be pushing.</param>
		public ElementStylePushContext(ElementStyleStack stack, ElementStyle style)
		{
			this._Stack = stack;
			this._Stack.Push(style);
		}

		#region Dispose functions

		protected void Dispose(bool disposing)
		{
			this._Stack.Pop();
		}

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		~ElementStylePushContext()
		{
			this.Dispose(false);
		}

		#endregion

		
	}
}
